home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / UStructureInspectors.cp < prev    next >
Encoding:
Text File  |  1994-02-20  |  10.1 KB  |  386 lines  |  [TEXT/MPS ]

  1. // UStructureInspectors.h
  2. //  Copyright  1984-1991 by Apple Computer Inc.    All rights reserved.
  3.  
  4. #include "UStructureInspectors.h"
  5.  
  6. #ifndef __UAPPLICATION__
  7. #include <UApplication.h>
  8. #endif
  9.  
  10. #ifndef __UWINDOW__
  11. #include <UWindow.h>
  12. #endif
  13.  
  14. #ifndef __UMACAPPUTILITIES__
  15. #include <UMacAppUtilities.h>
  16. #endif
  17.  
  18. //**************************************************************************************************
  19. //  TIdler                                                           
  20. //**************************************************************************************************
  21.  
  22. //--------------------------------------------------------------------------------------------------
  23. #pragma segment MyViewTools
  24.  
  25. TIdler::TIdler()
  26. {
  27. }
  28.  
  29. pascal void TIdler::Initialize()    // override 
  30. {
  31.     inherited::Initialize();
  32.     
  33.     fHandler = NULL;
  34. }
  35.  
  36. //--------------------------------------------------------------------------------------------------
  37.  
  38. pascal void TIdler::IIdler(TEventHandler *itsHandler)     
  39. {
  40.     this->IEventHandler(NULL);
  41.     
  42.     fHandler = itsHandler;
  43.     this->SetIdleFreq(fHandler->GetIdleFreq());
  44. }
  45.  
  46. //--------------------------------------------------------------------------------------------------
  47.  
  48. pascal Boolean TIdler::DoIdle(IdlePhase phase)    // override 
  49. {
  50.     if (fHandler)
  51.         return fHandler->DoIdle(phase);
  52.     else 
  53.         return FALSE;
  54. }
  55.  
  56. //**************************************************************************************************
  57. //  TObjectListView                                                           
  58. //**************************************************************************************************
  59. //--------------------------------------------------------------------------------------------------
  60.  
  61. pascal Boolean ListsMatch(TList *firstList,TList *secondList)
  62. {
  63.     if (firstList->GetSize() != secondList->GetSize())
  64.         return FALSE;
  65.     else
  66.     {
  67.         //return EqualBlocks(*((Handle) firstList), *((Handle) secondList),GetHandleSize((Handle) firstList));
  68.         for (ArrayIndex i = 1; i <= firstList->GetSize(); i++)
  69.         {
  70.             if (firstList->At(i) != secondList->At(i))
  71.                 return FALSE;
  72.         }
  73.         return TRUE;
  74.     }
  75. }
  76.  
  77. //--------------------------------------------------------------------------------------------------
  78.  
  79. TObjectListView::TObjectListView()
  80. {
  81. }
  82.  
  83. //--------------------------------------------------------------------------------------------------
  84.  
  85. pascal void TObjectListView::Initialize()    // override 
  86. {
  87.     inherited::Initialize();
  88.     
  89.     fAList = NULL;
  90.     fBList = NULL;
  91.     fDisplayedList = NULL;
  92.     fIdler = NULL;
  93. }
  94.  
  95. //--------------------------------------------------------------------------------------------------
  96. pascal void TObjectListView::DoPostCreate(TDocument *itsDocument)// override 
  97. {
  98.     inherited::DoPostCreate(itsDocument);
  99.  
  100.     FailInfo fi;
  101.     
  102.     if (fi.Try())
  103.     {
  104.         fAList = NewList();
  105.         fBList = NewList();
  106.         fDisplayedList = fAList;
  107.         
  108.         TIdler *anIdler = new TIdler;
  109.         anIdler->IIdler(this);
  110.         fIdler = anIdler;
  111.         fi.Success();
  112.     }
  113.     else
  114.     {
  115.         fAList = (TList*) FreeIfObject(fAList);
  116.         fBList = (TList*) FreeIfObject(fBList);
  117.         fIdler = (TIdler*) FreeIfObject(fIdler);
  118.         fDisplayedList = NULL;
  119.         fi.ReSignal();
  120.     }
  121.     
  122. }
  123.  
  124. //--------------------------------------------------------------------------------------------------
  125. pascal void TObjectListView::Free()    // Override 
  126. {
  127.     fAList = (TList*) FreeIfObject(fAList);
  128.     fBList = (TList*) FreeIfObject(fBList);
  129.     fIdler = (TIdler*) FreeIfObject(fIdler);
  130.     
  131.     inherited::Free();
  132. }
  133.  
  134. //--------------------------------------------------------------------------------------------------
  135.  
  136. pascal void TObjectListView::BuildList(TList *newList) 
  137. {
  138.     newList->DeleteAll();
  139. }
  140.  
  141. //--------------------------------------------------------------------------------------------------
  142. pascal Boolean TObjectListView::IsSynchronized() 
  143. {
  144.     TList *theNewList;
  145.     TList *theOldList;
  146.     
  147.     if (fDisplayedList == fAList)
  148.     {
  149.         theNewList = fBList;
  150.         theOldList = fAList;
  151.     }
  152.     else
  153.     {
  154.         theNewList = fAList;
  155.         theOldList = fBList;
  156.     }
  157.         
  158.     this->BuildList(theNewList);
  159.     return ListsMatch(theOldList,theNewList);
  160. }
  161.  
  162. //--------------------------------------------------------------------------------------------------
  163. pascal void TObjectListView::Synchronize(Boolean /* redraw */) 
  164. {
  165.     TList *theNewList;
  166.     TList *theOldList;
  167.     
  168.     if (fDisplayedList == fAList)
  169.     {
  170.         theNewList = fBList;
  171.         theOldList = fAList;
  172.     }
  173.     else
  174.     {
  175.         theNewList = fAList;
  176.         theOldList = fBList;
  177.     }
  178.  
  179.     this->BuildList(theNewList);
  180.     if (!ListsMatch(theOldList,theNewList))
  181.     {
  182.         TObject *selectedObject = this->GetSelectedObject();
  183.         
  184.         if (theOldList->GetSize() != theNewList->GetSize())
  185.         {
  186.             this->DelItemLast(fNumOfRows);
  187.             this->InsItemLast((short) theNewList->GetSize());
  188.         }
  189.         fDisplayedList = theNewList;
  190.         if (selectedObject)
  191.             this->SelectObject(selectedObject);
  192.         this->ScrollSelectionIntoView(!kRedraw);
  193.         this->ForceRedraw();
  194.     }    
  195. }
  196.  
  197. //--------------------------------------------------------------------------------------------------
  198.  
  199. pascal void TObjectListView::Draw(const VRect &area)        // Override 
  200. {
  201.     if (this->IsSynchronized())
  202.         inherited::Draw(area);
  203.     // Otherwise, let next idle synchronize
  204. }
  205.  
  206. //--------------------------------------------------------------------------------------------------
  207.  
  208. pascal Boolean TObjectListView::DoIdle(IdlePhase /*phase*/)    // override 
  209. {
  210.     this->Synchronize(kRedraw);
  211.     return FALSE;
  212. }
  213.  
  214. //--------------------------------------------------------------------------------------------------
  215.  
  216. pascal void TObjectListView::Open()    // override 
  217. {
  218.     gApplication->InstallCohandler(fIdler,TRUE);
  219.     inherited::Open();
  220. }
  221.  
  222. //--------------------------------------------------------------------------------------------------
  223.  
  224. pascal void TObjectListView::Close()    // override 
  225. {
  226.     gApplication->InstallCohandler(fIdler,FALSE);
  227.     inherited::Close();
  228. }
  229.  
  230. //--------------------------------------------------------------------------------------------------
  231. pascal TObject *TObjectListView::GetSelectedObject()
  232. {
  233.     return this->GetNthObject(this->FirstSelectedItem());
  234. }
  235.  
  236. //--------------------------------------------------------------------------------------------------
  237. pascal TObject *TObjectListView::GetNthObject(short n)
  238. {
  239.     if (fDisplayedList && (n > 0) && (n <= fDisplayedList->GetSize()))
  240.         return fDisplayedList->At(n);
  241.     else
  242.         return NULL;
  243. }
  244.  
  245. //--------------------------------------------------------------------------------------------------
  246. pascal void TObjectListView::SelectObject(TObject *anObject)
  247. {
  248.     ArrayIndex index = fDisplayedList->GetIdentityItemNo(anObject);
  249.     this->SelectItem((short) index,FALSE,TRUE,TRUE);
  250. }
  251.  
  252. //**************************************************************************************************
  253. //  TViewHierarchyView                                                           
  254. //**************************************************************************************************
  255.  
  256. //--------------------------------------------------------------------------------------------------
  257. TViewHierarchyView::TViewHierarchyView()
  258. {
  259. }
  260.  
  261. pascal void TViewHierarchyView::BuildList(TList *newList) // Override
  262. {
  263.     newList->DeleteAll();
  264.     this->FlattenHierarchy(NULL,newList);
  265. }
  266.  
  267. pascal void TViewHierarchyView::FlattenHierarchy(TView *root, TList *theList)
  268. {
  269.     if (root)
  270.     {
  271.         theList->InsertLast(root);
  272.  
  273.         CSubViewIterator iter(root);
  274.             
  275.         for (TView  *theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
  276.         {
  277.             this->FlattenHierarchy(theSubView, theList);
  278.         }        
  279.     }
  280.     else
  281.     {
  282.         CWMgrIterator iter;
  283.     
  284.         for (WindowPtr aWinPtr = iter.FirstWMgrWindow(); iter.More(); aWinPtr = iter.NextWMgrWindow())
  285.         {
  286.             TWindow  *aWindow = gApplication->WMgrToWindow(aWinPtr);
  287.             if (aWindow && (aWindow != this->GetWindow()))
  288.                 this->FlattenHierarchy(aWindow, theList);
  289.         }
  290.     }
  291. }
  292.  
  293. //--------------------------------------------------------------------------------------------------
  294.  
  295. pascal short GetDepth(TView *aView)
  296. {
  297.     if (aView->fSuperView == NULL)
  298.         return 0;
  299.     else
  300.         return 1 + GetDepth(aView->fSuperView);
  301. }
  302.  
  303. //--------------------------------------------------------------------------------------------------
  304.  
  305. pascal void TViewHierarchyView::GetItemText(short        anItem,
  306.                                          CStr255&    aString)// override 
  307. {    
  308.     if (anItem <= fDisplayedList->GetSize())
  309.     {
  310.         TView *theView = (TView*) this->GetNthObject(anItem);
  311.  
  312.         if (theView)
  313.         {
  314.             MAName itsName;
  315.             theView->GetClassName(itsName);        
  316.             CStr255 indentString = "......................................................................................................................";
  317.             indentString.Length() = GetDepth(theView) * 2;
  318.             
  319.             CStr255 IDString(theView->fIdentifier);        
  320.             aString = indentString + itsName + " '" + IDString + "'";
  321.         }
  322.         else
  323.             aString = "Error";
  324.     }
  325. }
  326.  
  327. //--------------------------------------------------------------------------------------------------
  328. pascal TView *TViewHierarchyView::GetSelectedView()
  329. {
  330.     return (TView*) this->GetSelectedObject();
  331. }
  332.  
  333. //**************************************************************************************************
  334. //  TTargetChainView                                                           
  335. //**************************************************************************************************
  336.  
  337. //--------------------------------------------------------------------------------------------------
  338.  
  339. pascal void FlattenTargetChain(TEventHandler *head, TList *theList)
  340. {
  341.     theList->InsertLast(head);
  342.     if (head->fNextHandler)
  343.         FlattenTargetChain(head->fNextHandler,theList);
  344. }
  345.  
  346. //--------------------------------------------------------------------------------------------------
  347.  
  348. TTargetChainView::TTargetChainView()
  349. {
  350. }
  351.  
  352. pascal void TTargetChainView::BuildList(TList *newList) // Override
  353. {
  354.     newList->DeleteAll();
  355.     FlattenTargetChain(gApplication->GetTarget(),newList);
  356. }
  357.  
  358. //--------------------------------------------------------------------------------------------------
  359.  
  360. pascal void TTargetChainView::GetItemText(short        anItem,
  361.                                          CStr255&    aString)// override 
  362. {    
  363.     if (anItem <= fDisplayedList->GetSize())
  364.     {
  365.         TEventHandler *theHandler = (TEventHandler*) this->GetNthObject(anItem);
  366.  
  367.         if (theHandler)
  368.         {
  369.             MAName itsName;
  370.             theHandler->GetClassName(itsName);        
  371.             
  372.             CStr255 IDString(theHandler->fIdentifier);        
  373.             aString = itsName + " '" + IDString + "'";
  374.         }
  375.         else
  376.             aString = "Error";
  377.         
  378.     }
  379. }
  380.  
  381. //--------------------------------------------------------------------------------------------------
  382. pascal TEventHandler *TTargetChainView::GetSelectedHandler()
  383. {
  384.     return (TEventHandler*) this->GetSelectedObject();
  385. }
  386.